package com.three.vip.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.three.core.entity.FrontUser;
import com.three.core.entity.ProductOrder;
import com.three.core.entity.UserBalanceLog;
import com.three.core.entity.UserIntegralLog;
import com.three.core.vo.R;
import com.three.vip.service.FrontUserService;
import com.three.vip.utils.Upload;
import com.three.vip.vo.AddCarVo;
import com.three.vip.vo.CustomerSearchFormVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author ：JinShiYan
 * @date ：Created in 2025/3/12 17:19
 * @description：
 * @modified By：
 * @version:
 */
@RestController
@RequestMapping("/vip/customer")
public class FrontUserController {

    @Autowired
    private FrontUserService frontUserService;

    @PostMapping("/CustomerManagement")
    public R<IPage<FrontUser>> CustomerManagement(@RequestBody CustomerSearchFormVo customerSearchFormVo){
        return frontUserService.selectByCondition(customerSearchFormVo);
    }

    @GetMapping("/getCustomerByName")
    public R<FrontUser> getCustomerByName(@RequestParam String userName){
        return frontUserService.getCustomerByName(userName);
    }

    @GetMapping("/getUserInfo")
    public R<FrontUser> getUserInfo(){
        return frontUserService.getUserInfo();
    }
    @PostMapping("/upload")
    public R uploadFile(MultipartFile file) {
        try {
            String url = Upload.uploadFile(file);
            return new R(200,"上传成功",url);
        } catch (Exception e) {
            return new R(500,"上传失败",null);
        }
    }
    @PostMapping("/updateInfo")
    public R<FrontUser> updateInfo(@RequestBody FrontUser frontUser){
        return frontUserService.updateInfo(frontUser);
    }

    @GetMapping("/selectBalanceDetail")
    public R<List<UserBalanceLog>> selectBalanceDetailById(Integer userId){
        return frontUserService.selectBalanceDetail(userId);
    }
    @GetMapping("/selectCreditsDetail")
    public R<List<UserIntegralLog>> selectCreditsDetailById(Integer userId){
        return frontUserService.selectCreditsDetail(userId);
    }

    @PostMapping("/updateFrontUserStatus")
    public R updateFrontUserStatus(@RequestBody FrontUser frontUser){
        return frontUserService.updateFrontUserStatus(frontUser);
    }

    @PostMapping("/insertFrontUser")
    public R insertFrontUser(@RequestBody AddCarVo addCarVo){
        return frontUserService.insertFrontUser(addCarVo);
    }
}
